package org.zyj.io.protocal.custom;

import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import org.zyj.io.protocal.Message;

import java.nio.charset.StandardCharsets;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ServerHandler extends SimpleChannelInboundHandler<Message> {
    private static final ExecutorService executorService = Executors.newFixedThreadPool(50);

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, Message msg) throws Exception {
        executorService.submit(() -> {
            System.out.println(msg);
            System.out.println(new String(msg.getBody())); //暂时不管字符串编码的问题

            ctx.writeAndFlush(Unpooled.copiedBuffer("已经接收到请求了", StandardCharsets.UTF_8)); // 返回客户端一个什么东西
        });
    }
}
